package design.patterns.proxymode.staticProxy.service;

import design.patterns.proxymode.staticProxy.api.IDrive;

import java.util.Random;

/**
 * @author ： cww
 * @date : 2018/7/5
 * 1.汽车行驶，实现drive接口
 * 2.并且对行驶计时
 */
public class Car implements IDrive {
    @Override
    public void drive() {
        //常规为了计时汽车行驶时间，直接在方法内部进行计时
        long start = System.currentTimeMillis();
        System.out.println("汽车启动");
        //模拟实现开车
        try {
            Thread.sleep(new Random().nextInt(1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("汽车停止");
        long end = System.currentTimeMillis();
        System.out.println("汽车行驶时间："+(end-start));

    }
}
